package com.jww.cloud.service.user.server.controller;

import cn.hutool.core.lang.Assert;
import com.jww.base.am.model.dos.SysUserDO;
import com.jww.base.am.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/users")
@Api(value = "用户管理", tags = "用户管理")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 根据用户ID查询用户
     *
     * @param userId 用户ID
     * @return SysUserDO
     * @author wanyong
     * @date 2017-12-05 13:35
     */
    @GetMapping("/{userId}")
    @ApiOperation(value = "单个查询", notes = "根据用户主键ID查询")
    public SysUserDO query(@ApiParam(value = "用户ID", required = true) @PathVariable(value = "userId") Long userId) {
        Assert.notNull(userId, "用户ID不能为空");
        return sysUserService.getById(userId);
    }

    /**
     * 根据用户名查询用户
     *
     * @param username 用户名
     * @return SysUserDO
     * @author wanyong
     * @date 2017-12-05 13:35
     */
    @GetMapping("/username/{username}")
    @ApiOperation(value = "单个查询", notes = "根据用户主键ID查询")
    public SysUserDO query(@ApiParam(value = "用户名", required = true) @PathVariable(value = "username") String username) {
        Assert.notNull(username, "用户名不能为空");
        return sysUserService.getByUsername(username);
    }
}
